package com.server.common.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.server.web.JSONSerielizer;

import flexjson.transformer.DateTransformer;

public class JSONUtil4TSY {

	public static DateTransformer dateFormater=new DateTransformer("yyyy-MM-dd'T'HH:mm:ss");
	
	
	 /**
	 * List 转 Json
	 * @param list
	 * @param totalCount
	 * @param pageSize
	 * @param pageIndex
	 * @param uid
	 * @param userName
	 * @param statusCode
	 * @param errInfor
	 * @return
	 * @author ServerZhang
	 * @date 2017年3月17日
	 */
	public static String list2Json(Integer level,
			List<Map<String,Object>> list, Integer totalCount,
			Integer pageSize, Integer pageIndex, String uid,
			String userName, Integer statusCode,String errInfor){	
		
		Map<String, Object> pMap = new HashMap<String, Object>();
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("L", list);
		map.put("N", pageSize);
		map.put("P", pageIndex);
		map.put("T", totalCount);
		
		String[] str = {level+""};
		pMap.put("G", str);
		
		pMap.put("UID", uid);
		pMap.put("UN", userName);
		pMap.put("c", statusCode);
		pMap.put("d", map);
		pMap.put("err", errInfor);
		pMap.put("tsy", "tsy");
		
		return JSONSerielizer.toJson(pMap, null, null);
	}
	/**
	 * Map 转 Json
	 * @param map
	 * @param uid
	 * @param userName
	 * @param statusCode
	 * @param errInfor
	 * @return
	 * @author ServerZhang
	 * @date 2017年3月18日
	 */
	public static String map2Json(Integer level,
			Map<String,Object> map,String uid,
			String userName, Integer statusCode,String errInfor){	
		
		Map<String, Object> pMap = new HashMap<String, Object>();
		
		String[] str = {level+""};
		pMap.put("G", str);
		
		pMap.put("UID", uid);
		pMap.put("UN", userName);
		pMap.put("c", statusCode);
		pMap.put("d", map);
		pMap.put("err", errInfor);
		pMap.put("tsy", "tsy");
		
		return JSONSerielizer.toJson(pMap, null, null);
	}
	 /**
	 * String 转 Json
	 * @param inputStr
	 * @param uid
	 * @param userName
	 * @param statusCode
	 * @param errInfor
	 * @return
	 * @author ServerZhang
	 * @date 2017年3月17日
	 */
	public static String str2Json(Integer level,
			String inputStr, String uid,
			String userName, Integer statusCode,String errInfor){	
		
		Map<String, Object> pMap = new HashMap<String, Object>();
		
		String[] str = {level+""};
		pMap.put("G", str);
		
		pMap.put("UID", uid);
		pMap.put("UN", userName);
		pMap.put("c", statusCode);
		pMap.put("d", inputStr);
		pMap.put("err", errInfor);
		pMap.put("tsy", "tsy");
		
		return JSONSerielizer.toJson(pMap, null, null);
	}
	
}
